import type { MusicPlayer } from '@/service/AudioController'
import type { UnwrapRef } from 'vue'

const StoreKey = 'AudioState'
// 保存数据到 localStorage
export function saveAudioState(state: UnwrapRef<MusicPlayer>): void {
    localStorage.setItem(StoreKey, JSON.stringify(state))
}

// 从 localStorage 获取数据
export function getAudioState(): MusicPlayer | null {
    const stateString = localStorage.getItem(StoreKey)
    if (stateString) {
        return JSON.parse(stateString)
    } else {
        return null
    }
}
